package com.easygoods.controller;

import com.bestvike.stone.spring.controller.BaseController;
import com.bestvike.stone.spring.page.PageableResponse;
import com.bestvike.stone.spring.rest.common.CommonResponse;
import com.bestvike.stone.spring.shiro.annotation.RequiresPermissions;
import com.easygoods.request.ChangePayPwdByOldRequest;
import com.easygoods.request.ChangePayPwdBySmsRequest;
import com.easygoods.request.DrawCashListRequest;
import com.easygoods.request.DrawCashRedoRequest;
import com.easygoods.request.DrawCashRequest;
import com.easygoods.response.DrawCashListResponse;
import com.easygoods.response.HasPayPwdResponse;
import com.easygoods.service.DrawCashService;
import com.easygoods.service.PayPwdService;
import com.easygoods.service.SmsService;
import com.easygoods.shiro.auth.UserPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 许崇雷 on 2019-02-20.
 */
@RestController
@RequestMapping(value = "/api/cash")
public class DrawCashController extends BaseController {
    @Autowired
    private DrawCashService drawCashService;
    @Autowired
    private PayPwdService payPwdService;
    @Autowired
    private SmsService smsService;

    //是否设置了支付密码
    @RequiresPermissions(UserPermissions.BUY)
    @GetMapping("/hasPayPwd")
    public CommonResponse<HasPayPwdResponse> hasPayPwd() {
        final HasPayPwdResponse response = this.payPwdService.hasPayPwd();
        return CommonResponse.success(response);
    }

    //发送修改支付密码验证码
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/sendChangePayPwdSms")
    public CommonResponse<Object> sendChangePayPwdSms() {
        this.smsService.sendChangePayPwdSms();
        return CommonResponse.success();
    }

    //修改支付密码 by sms
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/changePayPwdBySms")
    public CommonResponse<Object> changePayPwdBySms(@RequestBody ChangePayPwdBySmsRequest request) {
        this.payPwdService.changePayPwdBySms(request);
        return CommonResponse.success();
    }

    //修改支付密码 by 原来的 paypwd
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/changePayPwdByOld")
    public CommonResponse<Object> changePayPwdByOld(@RequestBody ChangePayPwdByOldRequest request) {
        this.payPwdService.changePayPwdByOld(request);
        return CommonResponse.success();
    }

    //提现
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/draw")
    public CommonResponse<Object> drawCash(@RequestBody DrawCashRequest request) {
        this.drawCashService.drawCash(request);
        return CommonResponse.success();
    }

    //重新提现
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/redraw")
    public CommonResponse<Object> redrawCash(@RequestBody DrawCashRedoRequest request) {
        this.drawCashService.redrawCash(request.getDrawCashId());
        return CommonResponse.success();
    }

    //查询
    @RequiresPermissions(UserPermissions.BUY)
    @PostMapping("/list")
    public CommonResponse<PageableResponse<DrawCashListResponse>> getDrawCashList(@RequestBody DrawCashListRequest request) {
        final PageableResponse<DrawCashListResponse> drawCashList = this.drawCashService.getDrawCashList(request);
        return CommonResponse.success(drawCashList);
    }
}
